package com.iplay.service.order.query;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.iplay.service.hotel.HotelService;
import com.iplay.service.query.QueryCondition;
import com.iplay.service.query.QueryConditionBuilder;
import com.iplay.service.query.QueryCondition.Operator;

@Component
public class HotelQueryConditionBuilder implements QueryConditionBuilder {

	@Autowired
	private HotelService hotelService;

	@Override
	public QueryCondition create(Object t) {
		QueryCondition con = null;
		List<Integer> hotels = hotelService.findHotelByName(String.class.cast(t));
		if (hotels.isEmpty())
			con = new QueryCondition("hotelId", -1);
		else if (hotels.size() == 1)
			con = new QueryCondition("hotelId", hotels.get(0));
		else
			con = new QueryCondition("hotelId", Operator.IN, hotels);
		return con;
	}

}
